// BorrowRecord.java - 借阅记录实体类
package com.library.entity;

import java.time.LocalDate;

public class BorrowRecord {
    private String recordId;
    private String readerId;
    private String bookIsbn;
    private LocalDate borrowDate;
    private LocalDate dueDate;
    private LocalDate returnDate;
    private int renewCount;
    private BorrowStatus status;
    private double fineAmount;

    public enum BorrowStatus {
        BORROWED, RETURNED, OVERDUE, LOST
    }

    public BorrowRecord(String recordId, String readerId, String bookIsbn, 
                       LocalDate borrowDate, LocalDate dueDate) {
        this.recordId = recordId;
        this.readerId = readerId;
        this.bookIsbn = bookIsbn;
        this.borrowDate = borrowDate;
        this.dueDate = dueDate;
        this.renewCount = 0;
        this.status = BorrowStatus.BORROWED;
        this.fineAmount = 0.0;
    }

    // Getter和Setter方法
    public String getRecordId() { return recordId; }
    public void setRecordId(String recordId) { this.recordId = recordId; }

    public String getReaderId() { return readerId; }
    public void setReaderId(String readerId) { this.readerId = readerId; }

    public String getBookIsbn() { return bookIsbn; }
    public void setBookIsbn(String bookIsbn) { this.bookIsbn = bookIsbn; }

    public LocalDate getBorrowDate() { return borrowDate; }
    public void setBorrowDate(LocalDate borrowDate) { this.borrowDate = borrowDate; }

    public LocalDate getDueDate() { return dueDate; }
    public void setDueDate(LocalDate dueDate) { this.dueDate = dueDate; }

    public LocalDate getReturnDate() { return returnDate; }
    public void setReturnDate(LocalDate returnDate) { this.returnDate = returnDate; }

    public int getRenewCount() { return renewCount; }
    public void setRenewCount(int renewCount) { this.renewCount = renewCount; }

    public BorrowStatus getStatus() { return status; }
    public void setStatus(BorrowStatus status) { this.status = status; }

    public double getFineAmount() { return fineAmount; }
    public void setFineAmount(double fineAmount) { this.fineAmount = fineAmount; }

    public boolean isOverdue() {
        return LocalDate.now().isAfter(dueDate) && status == BorrowStatus.BORROWED;
    }

    public long getOverdueDays() {
        if (isOverdue()) {
            return java.time.temporal.ChronoUnit.DAYS.between(dueDate, LocalDate.now());
        }
        return 0;
    }
}